<?php
    $error = array();
    if($_SERVER["REQUEST_METHOD"] === "POST"){
        // echo "开始处理数据";
        if(!$_POST["email"]){
                array_push($error, "email为必填项");
        }
        else{
            $email = ChechValue($_POST["email"]);
            if(!preg_match("/^\w+@\w+\.\w+$/", $email)){
                array_push($error, "邮箱格式有误");
            }
            else{

            }
        }
        if(!$_POST["mobile"]){
            array_push($error, "mobile为必填项");
        }
        else{
            $mobile = ChechValue($_POST["mobile"]);
            if(!preg_match("/^\w{6,}$/", $mobile)){
                array_push($error, "电话格式有误");
            }
            else{

            }
        }
        if(!$_POST["password"]){
            array_push($error, "password为必填项");
        }
        else{
            $password = ChechValue($_POST["password"]);
            if(!preg_match("/^\w+$/", $password)){
                array_push($error, "密码格式有误");
            }
            else{

            }
        }
    }

    function ChechValue($value){
        $data = trim($value);
        $data = htmlspecialchars($data);
        return $data;
    }


    $message = <<<EOT
    <script>alert('$error[0]'); history.go(-1);</script>
    EOT;

    if(count($error) > 0){
        echo $message;
    }
    else{
        echo "注册成功";
    }
?>
